package com.itqf.person;

import com.itqf.advice.FaceAdvice;
import com.itqf.advice.TransactionAdvice;
import com.itqf.face.Face;

/**
 * projectName: springframeworkgp8
 *
 * @author: 赵伟风
 * time: 2021/8/3 16:34
 * description: 代理类
 */
public class XingZheSun implements Face {


    private Face face;

    private FaceAdvice advice  = new FaceAdvice();
    private TransactionAdvice transactionAdvice = new TransactionAdvice();

    public XingZheSun(Face face) {
        this.face = face;
    }

    /**
     * 吃的行为
     */
    @Override
    public void eat() {

        advice.before();
        try {
            //开启事务
            transactionAdvice.before();
            face.eat();
            //事务提交
            transactionAdvice.returningAfter();
        }catch (Exception e)
        {
            //事务回滚
            transactionAdvice.thorwing();
        }finally {
            advice.after();
        }




    }

    @Override
    public void sleep() {

        advice.before();
        face.sleep();
        advice.after();

    }
}








